#!/bin/bash

echo "============================================"
echo "🔍 检查 Release 版本 API 问题"
echo "============================================"
echo ""

echo "[步骤 1/5] 检查是否使用了模型的 toJson() 方法..."
echo ""
if grep -rn "\.toJson()" lib/common/api/*.dart | grep -v "json.encode"; then
  echo "⚠️ 发现使用模型 toJson()，可能有问题！"
else
  echo "✅ 未发现使用模型 toJson() 的情况"
fi
echo ""

echo "[步骤 2/5] 检查请求模型类..."
echo ""
find lib/common/models -name "*request*.dart" -o -name "*_req.dart" 2>/dev/null
echo ""

echo "[步骤 3/5] 检查是否有 json_serializable 配置..."
echo ""
if grep -q "json_serializable" pubspec.yaml 2>/dev/null; then
  echo "✅ 已配置 json_serializable"
  grep "json_serializable" pubspec.yaml
else
  echo "ℹ️ 未使用 json_serializable"
fi
echo ""

echo "[步骤 4/5] 检查关键 API 文件..."
echo ""
if [ -f lib/common/api/friend_api.dart ]; then
  echo "✅ friend_api.dart 存在"
  grep -n "sender_id\|receiver_id" lib/common/api/friend_api.dart | head -10
else
  echo "❌ friend_api.dart 不存在！"
fi
echo ""

if [ -f lib/common/api/activity_api.dart ]; then
  echo "✅ activity_api.dart 存在"
  grep -n "publisherId\|activityId" lib/common/api/activity_api.dart | head -10
else
  echo "❌ activity_api.dart 不存在！"
fi
echo ""

echo "[步骤 5/5] 建议的修复措施..."
echo ""
echo "✅ 推荐方案：直接使用 Map 构建请求"
echo "   示例："
echo "   final requestData = {"
echo "     'sender_id': senderId,"
echo "     'receiver_id': receiverId,"
echo "     'timestamp': DateTime.now().millisecondsSinceEpoch ~/ 1000,"
echo "   };"
echo ""
echo "⚠️ 如果必须使用模型类："
echo "   1. 添加 json_serializable 依赖"
echo "   2. 使用 @JsonSerializable() 注解"
echo "   3. 运行 flutter pub run build_runner build"
echo "   4. 配置 ProGuard 规则"
echo ""

echo "============================================"
echo "📋 详细分析报告：Release版本ID缺失问题完整分析报告.md"
echo "============================================"

